package coolq

import (
	"fmt"
	"io/ioutil"
	"math"
	"math/rand"
	"net/http"
	"strconv"
	"strings"
	"sync"
	"time"

	"github.com/Mrs4s/MiraiGo/message"
	"github.com/Mrs4s/go-cqhttp/cache"
	"github.com/Mrs4s/go-cqhttp/lib"
	"github.com/Mrs4s/go-cqhttp/lib/qq"
	"github.com/Mrs4s/go-cqhttp/model"
	log "github.com/sirupsen/logrus"
)

const (
	QQ_MENU        = "菜单"
	QQ_MENU_EN     = "menu"
	QQ_QIANDAO     = "签到"
	QQ_QUERY       = "查询"
	QQ_FIVE        = "抢劫"
	QQ_COS         = "cos"
	QQ_FACE        = "face"
	QQ_XIAO        = "妹妹"
	QQ_MAIJIAXIU   = "买家秀"
	QQ_LOLICON     = "二次元萝莉"
	QQ_TIANGOURIJI = "舔狗日记"
	QQ_DUJITANG    = "毒鸡汤"
	QQ_CAIHONGPI   = "彩虹屁"
	QQ_GIRL_FULI   = "女神福利社"
	QQ_NEWS        = "news"
	QQ_NSFW        = "nsfw"
	QQ_TOUSU       = "投诉"
	QQ_CLEAR       = "clear"
	QQ_CLEARS      = "cls"
	QQ_TOP         = "top"
	QQ_RESET_COUNT = "resetcount"
	QQ_KLINE       = "kl"
	QQ_VIDEOS      = "sp"
	QQ_XIUXIAN     = "修仙"
	QQ_GOUMAI      = "购买"
	QQ_SHANGDING   = "商店"
	QQ_BEIBAO      = "背包"
	QQ_SABI        = "撒币"
	QQ_GUARD       = "罩起"
	QQ_HELP        = "help"
)

type RobotResponse struct {
	Audio   string
	Code    int
	Message string
	Resp    string
}

type UserInfo struct {
	Bot       *CQBot
	GroupCode int64
	UserID    int64
	Username  string
}

var c = cache.GetRedis()

const (
	// 抢劫5金币一次
	FIVE_ONE_PRICE int = 5
	// 能量罩
	FIVE_HOOD int = 100
)

// 自定义回复
func (bot *CQBot) dispatchGroupMessage(GroupCode int64, msg string, username string, userID int64, e []message.IMessageElement) {
	userinfo := &UserInfo{
		Bot:       bot,
		GroupCode: GroupCode,
		UserID:    userID,
		Username:  username,
	}

	if GroupCode == 318195769 {
		log := &model.ChatLog{
			GroupID:  GroupCode,
			UserID:   userID,
			Username: username,
			Message:  msg,
			AddTime:  time.Now(),
		}
		chatLog := &model.SendChat{
			GroupID:  GroupCode,
			UserID:   userID,
			Username: username,
			Message:  msg,
			AddTime:  time.Now(),
		}
		// 排除自家
		// reg := regexp.MustCompile(`-- from`)
		// if !reg.MatchString(msg) {
		// 	eles := make([]message.IMessageElement, 0)
		// 	for _, v := range e {
		// 		eles = append(eles, v)
		// 	}
		// 	eles = append(eles, message.NewText(fmt.Sprintf("\n-- from: Q群,name: %s", username)))
		// 	bot.SendGuildChannelMessage(21029471636646237, 1300118, &message.SendingMessage{
		// 		Elements: eles,
		// 	})
		// }
		// msg = strings.ReplaceAll(msg, "，", ",")
		model.AddLog(log)
		sendCount, _ := c.LimitLog(userID)
		if sendCount >= 5 {
			if sendCount == 5 {
				// 排除白名单
				if userID == 2854196306 {
					return
				}
				if g := bot.Client.FindGroup(GroupCode); g != nil {
					if m := g.FindMember(userID); m != nil {
						err := m.Mute(600)
						if err == nil {
							c.ClearBanUser(userID)
						}
					}
				}
				ele := make([]message.IMessageElement, 0)
				ele = append(ele, message.NewText(fmt.Sprintf("恶意刷屏！禁言10分钟！Q:%d.", userID)))
				bot.SendGroupMessage(GroupCode, &message.SendingMessage{
					Elements: ele,
				})
			}
			return
		}
		if len(msg) >= 13 && msg[:6] == QQ_TOUSU {
			// 禁言
			var user int64
			for _, elem := range e {
				switch o := elem.(type) {
				case *message.AtElement:
					if o.Target == 0 {
						continue
					}
					user = o.Target
				}
			}
			if user > 0 {
				if i, _ := c.GetLimitLog(userID); i >= 5 {
					if i == 5 {
						c.AddLimitLog(userID)
						sendAtMsg(userinfo, "当日举报次数已达上限！")
					}
					return
				}
				str := ""
				res, err := c.BanUser(user, userID)
				if err != nil {
					return
				}
				count := c.GetBanUser(user)
				ele := make([]message.IMessageElement, 0)
				num := int64(5)
				if count > 0 && count < num {
					if res == 1 {
						c.AddLimitLog(userID)
						ele = append(ele, message.NewText(fmt.Sprintf("投诉成功！Q:%d, 累计：%d次，超过%d次将被禁言5分钟。", user, count, num)))
					}
				} else if count >= num {
					if g := bot.Client.FindGroup(GroupCode); g != nil {
						if m := g.FindMember(user); m != nil {
							err := m.Mute(300)
							if err != nil {
								str = "机器人权限不足"
							} else {
								c.ClearBanUser(user)
								str = "成功"
							}
						} else {
							str = "失败"
						}
					}
					ele = append(ele, message.NewText(fmt.Sprintf("禁言！Q:%d,%s.", user, str)))
				}
				bot.SendGroupMessage(GroupCode, &message.SendingMessage{
					Elements: ele,
				})
			}
		} else if len(msg) >= 7 && msg[:6] == QQ_GOUMAI {
			// 购买
			menu := strings.Fields(msg)
			// 抢劫次数
			if len(menu) == 3 && menu[0] == QQ_GOUMAI && menu[1] == "1" {
				i, err := strconv.Atoi(menu[2])
				if err != nil || i < 0 {
					sendMsg(userinfo, "请输入正确的购买指令！")
					return
				}
				if model.GetUserCoinsByUserID(userID) < int64(i*FIVE_ONE_PRICE) {
					sendMsg(userinfo, "购买失败，余额不足！")
					return
				}
				// 正确的购买指令
				model.SetUserCoinsByUserID(userID, -int64(i*FIVE_ONE_PRICE), "购买抢劫扣除")
				success, err := c.BuyFiveLimit(userID, int64(i))
				if err != nil {
					sendMsg(userinfo, "购买异常！")
					return
				}
				sendMsg(userinfo, fmt.Sprintf("购买成功，当前剩余次数：%d", success))
				return
			} else if len(menu) == 3 && menu[0] == QQ_GOUMAI && menu[1] == "2" {
				// 能量罩
				i, err := strconv.Atoi(menu[2])
				if err != nil || i < 0 {
					sendMsg(userinfo, "请输入正确的购买指令！")
					return
				}
				if model.GetUserCoinsByUserID(userID) < int64(i*FIVE_HOOD) {
					sendMsg(userinfo, "购买失败，余额不足！")
					return
				}
				model.SetUserCoinsByUserID(userID, -int64(i*FIVE_HOOD), "购买能量罩扣除")
				success, err := c.BuyGuard(userID, int64(i))
				if err != nil {
					sendMsg(userinfo, "购买异常！")
					return
				}
				sendMsg(userinfo, fmt.Sprintf("购买成功，当前剩余次数：%d", success))
				return
			}
			sendMsg(userinfo, "请输入正确的购买指令！")
			return
		} else if len(msg) >= 7 && msg[:6] == QQ_XIUXIAN {
			// 修仙
			i, err := strconv.Atoi(strings.TrimSpace(msg[6:]))
			if err != nil {
				return
			}
			if i < 1 || i > 360 {
				sendAtMsg(userinfo, "超出人类可修仙的范围！")
				return
			}
			if g := bot.Client.FindGroup(GroupCode); g != nil {
				if m := g.FindMember(userID); m != nil {
					err := m.Mute(uint32(i * 60))
					if err != nil {
						str := "机器人权限不足"
						sendMsg(userinfo, str)
						return
					}
					c.ClearBanUser(userID)
					model.SetUserCoinsByUserID(userID, int64(i), "修仙获得")
					sendAtMsg(userinfo, fmt.Sprintf("修仙成功！,%d分钟后出关.", i))
				}
			}
		} else if len(msg) >= 13 && msg[:6] == QQ_FIVE {
			// 修仙
			i, err := strconv.Atoi(strings.Split(strings.TrimSpace(msg[6:]), "[")[0])
			if err != nil || i < 0 {
				i = 1
			}
			if i > 30 {
				i = 30
			}
			// five
			var user int64
			for _, elem := range e {
				switch o := elem.(type) {
				case *message.AtElement:
					if o.Target == 0 {
						continue
					}
					user = o.Target
				}
			}
			if user > 0 {
				var str_all string
				var res_all int64
				if c.GetXiuxian(user) {
					str_all = "对方有防护罩状态！请勿打扰！"
				} else {
					var str string
					var sum chan int64
					var res chan string
					var wu sync.Mutex
					var wg sync.WaitGroup
					res = make(chan string, i)
					sum = make(chan int64, i)
					wg.Add(i)
					for ii := 0; ii < cap(res); ii++ {
						go func(i int64) {
							wu.Lock()
							flag, coins := qq.Five(userID, user, i)
							wu.Unlock()
							if flag == 0 {
								str = "对方这个穷逼不配给你抢劫了！"
							} else if flag == -1 {
								str = "今天你的抢劫次数用完了！可以花20金币购买一次！"
							} else if flag == 1 {
								str = "你自己穷就不要上街晃荡了！"
							} else {
								if coins == 0 {
									str = "你遇到了起鼓相当的对手。双方打成平手！"
								} else if coins > 40 {
									str = fmt.Sprintf("+%02d|⚔️对方受不住你的一招，就灰溜溜的跑了！赢得了%d金币！", coins, coins)
								} else if coins > 30 {
									str = fmt.Sprintf("+%02d|⚔️对方和你过了五招,还是败给了你，赢得了%d金币！", coins, coins)
								} else if coins > 0 {
									str = fmt.Sprintf("+%02d|⚔️对方和你拼命，还是输给了你,赢得了%d金币！", coins, coins)
								} else if coins < -25 {
									str = fmt.Sprintf("%02d|⚔️招架不住对方一招就输掉了，默默的交出了%d金币！", coins, int(math.Abs(float64(coins))))
								} else if coins < 0 {
									str = fmt.Sprintf("%02d|⚔️和对方迂回了五个回合，你还是输掉了，交出了%d金币！", coins, int(math.Abs(float64(coins))))
								}
							}
							sum <- coins
							res <- str
							wg.Done()
						}(int64(ii))
					}
					wg.Wait()
					for ii := 0; ii < cap(res); ii++ {
						res_all += <-sum
						str_all += fmt.Sprintf("\n%s", <-res)
					}
				}
				sendAtMsg(userinfo, fmt.Sprintf("%s\n总收益：%d", str_all, res_all))
			}
		} else if len(msg) >= 8 && msg[:6] == QQ_XIAO {
			model.ChatAddLog(chatLog)
			robot(bot, GroupCode, msg[7:])
		} else if len(msg) >= 3 && msg[:2] == QQ_KLINE {
			model.ChatAddLog(chatLog)
			getStock(bot, GroupCode, msg[3:])
		} else if len(msg) >= 3 && msg[:2] == QQ_VIDEOS {
			model.ChatAddLog(chatLog)
			getVideo(bot, GroupCode, msg[3:])
		} else {
			switch strings.ToLower(msg) {
			case QQ_HELP, QQ_MENU, QQ_MENU_EN:
				sendMsg(userinfo, `菜单：
- cos  
- 妹妹 xxx (xxx:百度图库搜索）
- 图片类: 女神福利社,买家秀,二次元萝莉
- 文字类: 毒鸡汤,彩虹屁,舔狗日记
- 功能类: 签到,查询,抢劫[次数],商店,背包
- 修仙 xxx(通过禁言获得金币，1金币=1分钟，每次上限360分钟)
- 技能：罩起
- nsfw (同 clear,cls)
- top
- resetcount
- news`)
			case QQ_SHANGDING:
				sendMsg(userinfo, fmt.Sprintf(`商品列表：
- ---
- 1. 抢劫次数（%d金币/次）
- 2. 防抢劫能量罩(%d金币/个)
- 3. 其他的开发中...
- ---
- 使用方式：购买 商品列表 次/个数
- 如： 购买 1 1
- ---`, FIVE_ONE_PRICE, FIVE_HOOD))
			case QQ_QIANDAO:
				flag, coins := qq.Signin(userID)
				if flag != 0 {
					sendAtMsg(userinfo, fmt.Sprintf("签到成功，获取%d金币！", coins))
				}
			case QQ_GUARD:
				// 能量罩
				if i, err := c.GetBuyGuard(userID); err == nil {
					if c.GetXiuxian(userID) {
						sendMsg(userinfo, "已经使用过能量罩")
						return
					}
					if i > 0 {
						c.SetXiuxian(userID, 360*60)
						c.BuyGuard(userID, -1)
						sendAtMsg(userinfo, "能量罩开启成功")
						return
					}
				}
				sendMsg(userinfo, "你还没购买能量罩")
			case QQ_QUERY:
				coins := model.GetUserCoinsByUserID(userID)
				d := model.GetAccountLogByUserID(userID)
				str := ""
				for i, al := range d {
					str += fmt.Sprintf("\n%d: %d[%s]", i, al.Coins, al.Remarks)
				}
				sendAtMsg(userinfo, fmt.Sprintf("你的背包有%d金币！%s", coins, str))
			case QQ_BEIBAO:
				coins := model.GetUserCoinsByUserID(userID)
				num, err := c.GetBuyFiveLimit(userID)
				if err != nil {
					num = 0
				}
				str := ""
				if num != 0 {
					str += fmt.Sprintf("\n⚔️抢劫技能：%d次", num)
				}
				num1, err := c.GetBuyGuard(userID)
				if err != nil {
					num1 = 0
				}
				if num1 != 0 {
					str += fmt.Sprintf("\n💫能量罩：%d个", num1)
				}
				sendAtMsg(userinfo, fmt.Sprintf("\n💰你的背包有%d金币！\n%s", coins, str))
			case QQ_COS:
				// 扣费
				if model.SetUserCoinsByUserID(userID, -5, "查看cos扣除") == -999 {
					sendMsg(userinfo, "余额不足")
					return
				}
				model.ChatAddLog(chatLog)
				imgUrl, err := lib.GetImage()
				var ele []message.IMessageElement
				if err != nil {
					ele = make([]message.IMessageElement, 0)
					ele = append(ele, message.NewText("images not found"))
				} else {
					imgPath, err := lib.DownloadImage(imgUrl)
					if err != nil {
						return
					}
					imgEle, err := bot.Client.UploadGroupImageByFile(GroupCode, imgPath)
					if err != nil {
						return
					}
					ele = append(ele, imgEle)
				}
				bot.SendGroupMessage(GroupCode, &message.SendingMessage{
					Elements: ele,
				})
			case QQ_FACE:
				ele := make([]message.IMessageElement, 0)
				id := rand.Int31n(321)
				ele = append(ele, message.NewFace(id))
				bot.SendGroupMessage(GroupCode, &message.SendingMessage{
					Elements: ele,
				})
			case QQ_GIRL_FULI:
				model.ChatAddLog(chatLog)
				imgUrl := lib.GetFuliShe()
				if imgUrl != "" {
					ele := bot.ConvertStringMessage(fmt.Sprintf("[CQ:video,file=%s]", imgUrl), MessageSourceGroup)
					bot.SendGroupMessage(GroupCode, &message.SendingMessage{
						Elements: ele,
					})
				} else {
					sendMsg(userinfo, "福利社 load failed")
				}
			case QQ_TIANGOURIJI:
				model.ChatAddLog(chatLog)
				resp, err := lib.HttpGet("https://api.ixiaowai.cn/tgrj/index.php")
				if err == nil && resp.StatusCode == http.StatusOK {
					body, err := ioutil.ReadAll(resp.Body)
					if err == nil {
						ele := make([]message.IMessageElement, 0)
						ele = append(ele, message.NewText(string(body)))
						bot.SendGroupMessage(GroupCode, &message.SendingMessage{
							Elements: ele,
						})
					}

				}
			case QQ_DUJITANG:
				model.ChatAddLog(chatLog)
				tb := &lib.MuxiaoguoApi{}
				err := lib.RequestDujitang("https://api.muxiaoguo.cn/api/dujitang", tb)
				if err != nil {
					fmt.Printf("err: %v\n", err)
				}
				if tb.Code == "200" && tb.Data.Comment != "" {
					ele := make([]message.IMessageElement, 0)
					ele = append(ele, message.NewText(string(tb.Data.Comment)))
					bot.SendGroupMessage(GroupCode, &message.SendingMessage{
						Elements: ele,
					})
				}
			case QQ_CAIHONGPI:
				model.ChatAddLog(chatLog)
				tb := &lib.MuxiaoguoApi{}
				err := lib.RequestDujitang("https://api.muxiaoguo.cn/api/caihongpi", tb)
				if err != nil {
					fmt.Printf("err: %v\n", err)
				}
				if tb.Code == "200" && tb.Data.Comment != "" {
					ele := make([]message.IMessageElement, 0)
					ele = append(ele, message.NewText(string(tb.Data.Comment)))
					bot.SendGroupMessage(GroupCode, &message.SendingMessage{
						Elements: ele,
					})
				}
			case QQ_NEWS:
				lists := lib.GetQiKe()
				if len(lists) > 0 {
					ele := make([]message.IMessageElement, 0)
					for k, v := range lists {
						ele = append(ele, message.NewText(k+"\n"+v+"\n"))
						ele = append(ele, message.NewText("---\n"))
					}
					bot.SendGroupMessage(GroupCode, &message.SendingMessage{
						Elements: ele,
					})
				}
			case QQ_RESET_COUNT:
				res, err := c.ResetTopByUserID(userID)
				if err != nil {
					return
				}
				if res == "OK" {
					model.DelSendChatByUserID(userID)
					sendMsg(userinfo, "重置成功，一周只能重置一次！")
				}
			case QQ_TOP:
				lists := model.GetSendChatDataByUserID(userID)
				str := fmt.Sprintf("[%s] top: \n", username)
				if len(lists) > 0 {
					for k, v := range lists {
						str += fmt.Sprintf("%d. %s(%d)\n", k, v.Message, v.Count)
					}
				} else {
					str += "良好市民！"
				}
				sendMsg(userinfo, str)
			case QQ_NSFW, QQ_CLEAR, QQ_CLEARS:
				enter := strings.Repeat("\n", 40)
				sendMsg(userinfo, enter)
			case QQ_MAIJIAXIU:
				model.ChatAddLog(chatLog)
				// 扣费
				if model.SetUserCoinsByUserID(userID, -5, "查看买家秀扣除") == -999 {
					sendMsg(userinfo, "余额不足")
					return
				}
				tb := &lib.TBData{}
				err := lib.RequestTB("https://api.vvhan.com/api/tao?type=json", tb)
				if err != nil {
					fmt.Printf("err: %v\n", err)
				}
				if tb.Pic != "" {
					ele := bot.ConvertStringMessage(fmt.Sprintf("[CQ:image,file=%s]", tb.Pic), MessageSourceGroup)
					bot.SendGroupMessage(GroupCode, &message.SendingMessage{
						Elements: ele,
					})
				}
			case QQ_LOLICON:
				model.ChatAddLog(chatLog)
				// 扣费
				if model.SetUserCoinsByUserID(userID, -5, "查看二次元萝莉扣除") == -999 {
					sendMsg(userinfo, "余额不足")
					return
				}
				lolicon := &lib.Lolicon{}
				err := lib.RequestLolicon("https://api.lolicon.app/setu/v2", lolicon)
				if err != nil || lolicon.Error != "" {
					break
				}
				if len(lolicon.Data) <= 0 {
					break
				}
				imgUrl := lolicon.Data[0].Urls.Original
				ele := bot.ConvertStringMessage(fmt.Sprintf("[CQ:image,file=%s]", imgUrl), MessageSourceGroup)
				ele = append(ele, message.NewText(lolicon.Data[0].Title))
				bot.SendGroupMessage(GroupCode, &message.SendingMessage{
					Elements: ele,
				})
			}
		}

	}
}

func getVideo(bot *CQBot, GroupCode int64, msg string) {
	imgUrl := lib.GetVideoByType(msg)
	if imgUrl != "" {
		ele := bot.ConvertStringMessage(fmt.Sprintf("[CQ:video,file=%s]", imgUrl), MessageSourceGroup)
		bot.SendGroupMessage(GroupCode, &message.SendingMessage{
			Elements: ele,
		})
	} else {
		ele := make([]message.IMessageElement, 0)
		ele = append(ele, message.NewText("video load failed"))
		bot.SendGroupMessage(GroupCode, &message.SendingMessage{
			Elements: ele,
		})
	}
}

func robot(bot *CQBot, GroupCode int64, msg string) {
	switch msg {
	case "list":
		l := lib.GetLabelList(10)
		var context = "list: \n"
		for _, v := range l {
			context += "  - " + v + "\n"
		}
		ele := make([]message.IMessageElement, 0)
		ele = append(ele, &message.TextElement{
			Content: context,
		})
		bot.SendGroupMessage(GroupCode, &message.SendingMessage{
			Elements: ele,
		})
	default:
		var ele []message.IMessageElement
		s := lib.GetLabel(msg)
		if s != "" {
			imgUrl, err := lib.GetImageUrl(s)
			if err != nil {
				ele = make([]message.IMessageElement, 0)
				ele = append(ele, message.NewText("images not found"))
			} else {
				imgPath, err := lib.DownloadImageByMeizi(imgUrl)
				if err != nil {
					return
				}
				imgEle, err := bot.Client.UploadGroupImageByFile(GroupCode, imgPath)
				if err != nil {
					return
				}
				ele = append(ele, imgEle)
			}
			bot.SendGroupMessage(GroupCode, &message.SendingMessage{
				Elements: ele,
			})
			return
		}
		// 百度图库
		if len(msg) > 0 {
			imgUrl, err := lib.GetBaiduImage(msg)
			if err != nil {
				ele = make([]message.IMessageElement, 0)
				ele = append(ele, message.NewText("baiduImages not found"))
			} else {
				imgPath, err := lib.DownloadImage(imgUrl)
				if err != nil {
					log.Error("baidu err:", err)
					return
				}
				imgEle, err := bot.Client.UploadGroupImageByFile(GroupCode, imgPath)
				if err != nil {
					log.Error("baidu err:", err)
					return
				}
				ele = append(ele, imgEle)
			}
			bot.SendGroupMessage(GroupCode, &message.SendingMessage{
				Elements: ele,
			})
		}
	}
}

func getStock(bot *CQBot, GroupCode int64, msg string) {
	_, err := strconv.Atoi(msg)
	if err != nil {
		str := lib.SearchStock(msg)
		imgUrl := fmt.Sprintf("https://image.sinajs.cn/newchart/min/n/%s.png?%d", str, time.Now().Unix())
		if lib.CheckImageUrl(imgUrl) {
			ele := bot.ConvertStringMessage(fmt.Sprintf("[CQ:image,file=%s]", imgUrl), MessageSourceGroup)
			bot.SendGroupMessage(GroupCode, &message.SendingMessage{
				Elements: ele,
			})
			return
		}
		return
	}
	imgUrl := fmt.Sprintf("http://image.sinajs.cn/newchart/min/n/sh%s.gif?%d", msg, time.Now().Unix())
	if lib.CheckImageUrl(imgUrl) {
		ele := bot.ConvertStringMessage(fmt.Sprintf("[CQ:image,file=%s]", imgUrl), MessageSourceGroup)
		bot.SendGroupMessage(GroupCode, &message.SendingMessage{
			Elements: ele,
		})
		return
	}
	imgUrl = fmt.Sprintf("http://image.sinajs.cn/newchart/min/n/sz%s.gif?%d", msg, time.Now().Unix())
	if lib.CheckImageUrl(imgUrl) {
		ele := bot.ConvertStringMessage(fmt.Sprintf("[CQ:image,file=%s]", imgUrl), MessageSourceGroup)
		bot.SendGroupMessage(GroupCode, &message.SendingMessage{
			Elements: ele,
		})
		return
	}
	imgUrl = fmt.Sprintf("http://image.sinajs.cn/newchart/min/n/hk%s.gif?%d", msg, time.Now().Unix())
	if lib.CheckImageUrl(imgUrl) {
		ele := bot.ConvertStringMessage(fmt.Sprintf("[CQ:image,file=%s]", imgUrl), MessageSourceGroup)
		bot.SendGroupMessage(GroupCode, &message.SendingMessage{
			Elements: ele,
		})
		return
	}
}

func sendMsg(userinfo *UserInfo, msg string) {
	ele := make([]message.IMessageElement, 0)
	ele = append(ele, message.NewText(msg))
	userinfo.Bot.SendGroupMessage(userinfo.GroupCode, &message.SendingMessage{
		Elements: ele,
	})
}

func sendAtMsg(userinfo *UserInfo, msg string) {
	ele := make([]message.IMessageElement, 0)
	ele = append(ele, message.NewAt(userinfo.UserID, "@"+userinfo.Username))
	ele = append(ele, message.NewText(msg))
	userinfo.Bot.SendGroupMessage(userinfo.GroupCode, &message.SendingMessage{
		Elements: ele,
	})
}
